package main

import (
	"errors"
	"net/http"
	"net/rpc"
)

// Operation 四则运输参数结构体
type Operation struct {
	Value1 int
	Value2 int
}

// Ans 结果结构体
type Ans struct {
}

func (a *Ans) Add(params Operation, ret *int) error {
	*ret = params.Value1 + params.Value2
	return nil
}
func (a *Ans) Multiplication(params Operation, ret *int) error {
	*ret = params.Value1 * params.Value2
	return nil
}

func (a *Ans) Division(params Operation, ret *int) error {
	if params.Value2 == 0 || params.Value1 == 0 {
		return errors.New("除数，被除数不能为0")
	}
	*ret = params.Value1 / params.Value2
	return nil
}

func main() {
	ans := new(Ans)
	err := rpc.Register(ans)
	if err != nil {
		panic(err)
	}
	rpc.HandleHTTP()
	err = http.ListenAndServe(":8080", nil)
	if err != nil {
		panic(err)
	}

}
